//
//  LYSystemMessagefViewController.m
//  artist
//
//  Created by laotang on 16/5/23.
//  Copyright © 2016年 viviyoo. All rights reserved.
//

#import "LYSystemMessagefViewController.h"
#import "LYSystemMessageCell.h"
#import "LYMyIntegralListModel.h"
static NSString *messageCellID = @"LYSystemMessageCellId";

@interface LYSystemMessagefViewController ()<UITableViewDataSource, UITableViewDelegate>

@property(nonatomic, strong) NSArray *messageArray;

@end

@implementation LYSystemMessagefViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        self.edgesForExtendedLayout =  UIRectEdgeNone;
    }
    
   self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0f, 0.0f,self.view.frame.size.width,self.view.frame.size.height-108) style:UITableViewStylePlain];
    [self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 0, 49, 0)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    


    
//    UINib * nib =

    [self.view addSubview:self.tableView];
    
    UINib *nib = [UINib nibWithNibName:NSStringFromClass([LYSystemMessageCell class]) bundle:nil];
    [self.tableView registerNib:nib forCellReuseIdentifier:messageCellID];
//    self.tableView.contentInset = 

    [self getUnreadMessage];
    
}


- (void)getUnreadMessage{
    [LYRequestTool getUnreadListMessageWithToken:[AppDelegate shareInstance].token success:^(NSArray<LYMyMessageListModel *> *array) {
        self.messageArray = array;
        [self.tableView reloadData];
    } failure:^(NSString *code, NSString *message) {
        [MBProgressHUD showError:message];
    }];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.messageArray.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LYSystemMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:messageCellID];
    
    cell.message = self.messageArray[indexPath.row];
    return  cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}
@end
